package crp.core.user.domain.services;

import com.qwlabs.panache.Ranged;
import crp.core.user.domain.models.UserEntity;
import crp.core.user.domain.repositories.UserRepository;
import io.quarkus.panache.common.Range;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.Collection;
import java.util.Optional;
import java.util.stream.Stream;

@ApplicationScoped
public class UserSearcher {
    private final UserRepository userRepository;

    @Inject
    public UserSearcher(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    public Optional<UserEntity> byId(String id) {
        return userRepository.findByIdOptional(id);
    }

    public Stream<UserEntity> byIds(Collection<String> ids) {
        return userRepository.findByIds(ids);
    }

    public Ranged<UserEntity> by(String keyword, Range range) {
        return Ranged.of(userRepository.findBy(keyword), range);
    }
}
